﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Time.Utility
{
    public class DataConvert
    {
        #region Hex
        public static byte[] HexStrTobyte(string hexString)
        {
            hexString = hexString.Replace(" ", "");
            if ((hexString.Length % 2) != 0)
                hexString += " ";
            byte[] returnBytes = new byte[hexString.Length / 2];
            for (int i = 0; i < returnBytes.Length; i++)
                returnBytes[i] = Convert.ToByte(hexString.Substring(i * 2, 2).Trim(), 16);
            return returnBytes;
        }
        #endregion   

        public static Int32 BytesToInt(Byte[] buffer)
        {
            if (buffer != null)
            {
                StringBuilder sb = new StringBuilder(buffer.Length * 8);
                foreach (byte b in buffer)
                {
                    sb.Append(Convert.ToString(b, 2).PadLeft(8, '0'));
                }
                string strResult = sb.ToString();
                return Convert.ToInt32(strResult, 2);
            }
            else
                return 0;
        }

        public static Int32 BytesToDouble(Byte[] buffer)
        {
            if (buffer != null)
            {
                StringBuilder sb = new StringBuilder(buffer.Length * 4);

                sb.Append(Convert.ToString(buffer[0], 2).PadLeft(8, '0'));
                sb.Append(Convert.ToString(buffer[1], 2).PadLeft(8, '0'));
                string strResult = sb.ToString();
                return Convert.ToInt32(strResult,2);     
            }
            else
                return 0;
            
        }

        public static string  GetShift()
        {
            Int32 hour = Int32.Parse(DateTime.Now.ToString("HH"));
            if (hour > 8 && hour < 18)
                return "白班";
            else
                return "晚班";
        }


    }
}
